package com.resys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.resys.entity.enums.PageSize;
import com.resys.entity.query.CancellationrequestQuery;
import com.resys.entity.po.Cancellationrequest;
import com.resys.entity.vo.PaginationResultVO;
import com.resys.entity.query.SimplePage;
import com.resys.mappers.CancellationrequestMapper;
import com.resys.service.CancellationrequestService;
import com.resys.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("cancellationrequestService")
public class CancellationrequestServiceImpl implements CancellationrequestService {

	@Resource
	private CancellationrequestMapper<Cancellationrequest, CancellationrequestQuery> cancellationrequestMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Cancellationrequest> findListByParam(CancellationrequestQuery param) {
		return this.cancellationrequestMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(CancellationrequestQuery param) {
		return this.cancellationrequestMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Cancellationrequest> findListByPage(CancellationrequestQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Cancellationrequest> list = this.findListByParam(param);
		PaginationResultVO<Cancellationrequest> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Cancellationrequest bean) {
		return this.cancellationrequestMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Cancellationrequest> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.cancellationrequestMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Cancellationrequest> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.cancellationrequestMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Cancellationrequest bean, CancellationrequestQuery param) {
		StringTools.checkParam(param);
		return this.cancellationrequestMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(CancellationrequestQuery param) {
		StringTools.checkParam(param);
		return this.cancellationrequestMapper.deleteByParam(param);
	}

	/**
	 * 根据CancellationId获取对象
	 */
	@Override
	public Cancellationrequest getCancellationrequestByCancellationId(Integer cancellationId) {
		return this.cancellationrequestMapper.selectByCancellationId(cancellationId);
	}

	/**
	 * 根据CancellationId修改
	 */
	@Override
	public Integer updateCancellationrequestByCancellationId(Cancellationrequest bean, Integer cancellationId) {
		return this.cancellationrequestMapper.updateByCancellationId(bean, cancellationId);
	}

	/**
	 * 根据CancellationId删除
	 */
	@Override
	public Integer deleteCancellationrequestByCancellationId(Integer cancellationId) {
		return this.cancellationrequestMapper.deleteByCancellationId(cancellationId);
	}
}